#ifdef _WIN32
#include <Windows.h>
#endif
#include <cmath>
#include <gl/GL.h>
#include <gl/GLU.h>
#include "Camera.h"

const float Camera::rotSpeed = 0.003f;
const float Camera::moveSpeed = 0.05f;

Camera::Camera() : x(), y(), z(), xrot(), yrot(), lx(), ly(0.0f), lz(-1.0f), dirX(-1.0f), dirY(0.0f)
{
}

Camera::Camera(float x, float y, float z, float xrot, float yrot, float lx, float ly, float lz) 
	: x(x), y(y), xrot(xrot), yrot(yrot), lx(lx), ly(ly), lz(lz)
{
}

void Camera::moveX(int dir)
{
	x = x + dir * lx * moveSpeed;

	glLoadIdentity();
	gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0.0f, 1.0f, 0.0f);
}

void Camera::moveZ(int dir)
{
	z = z + dir * lz * moveSpeed;

	glLoadIdentity();
	gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0.0f, 1.0f, 0.0f);
}

void Camera::moveForward(int dir)
{
	x = x + dir * lx * moveSpeed;
	z = z + dir * lz * moveSpeed;

	glLoadIdentity();
	gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0.0f, 1.0f, 0.0f);
}

void Camera::orient()
{
	lx = sin(yrot);
	lz = -cos(yrot);

	glLoadIdentity();

	gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0.0f, 1.0f, 0.0f);
}

void Camera::moveTo(float x, float y, float z)
{
	this->x = x;
	this->y = y;
	this->z = z;

	glLoadIdentity();
	gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0.0f, 1.0f, 0.0f);
}

float Camera::nextX(int dir)
{
	return x + dir * lx * moveSpeed;
}

float Camera::nextZ(int dir)
{
	return z + dir * lz * moveSpeed;
}